<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var p = {
            id: 7748,
            name: 'sam',
            age: 20,
            time: new Date()
        }
        let set = new Set();
        let set2 = new Set([1, 2, 3, 4, 5, 6, 7]);
        console.log(set);
        console.log(set2);
        set2.add('admin');
        set2.add(2);//重复的不能存放，即添加失败
        set2.delete(2)//根据值删除，set没有索引
        set2.add(33).add(44).add(55).delete(44);//链式操作
        console.log(set.has(44));//false
        // set2.clear();//清除set
        set2.add(p)
        console.log(set2);
        console.log(set2.values());//获取值的集合（迭代器）

        // 遍历1
        set2.forEach(function (value) {
            console.log(value);
        })

        // 遍历2
        for (let value of set2) {
            console.log(value);
        }

        let [...arr] = set2;//set 转 数组
        console.log(arr);
        let s = new Set(arr);// 数组 转 set
        console.log(s);
    </script>
</body>

</html>